﻿using Abp.Hangfire;
using Abp.Modules;
using Basefr.Modules;

namespace Basefr.Async
{
    [DependsOn(
        typeof(AbpHangfireAspNetCoreModule),
        //typeof(AbpQuartzModule),
        typeof(Basefr.Module))]
    public class Module : ModuleBase<Module>
    {
        public override void PreInitialize()
        {
            //集成HangFire
            //Configuration.BackgroundJobs.UseHangfire();
        }

        public override void PostInitialize()
        {
            ////使用Quartz.Net
            ////Quartz.Net执行时间可精确到毫秒级别
            ////Quartz.Net不可启动多个实例，默认未指定JobStore或配置文件时，使用内存保存Schedule信息，建议只在Dispatcher控制台程序中注册定时任务，普通Web程序不注册不启动，大多数场景够用了
            //var scheduler = IocManager.Resolve<IQuartzScheduleJobManager>();

            //scheduler.ScheduleAsync<TestTask>(
            //    job => job.WithIdentity("MyTestTask", "MyGroup").WithDescription("Task Description..."),
            //    trigger => trigger.StartNow().WithSimpleSchedule(schedule => schedule.WithIntervalInSeconds(3).Build()));

            ////不建议使用ABP内置的Background Worker，无法持久化，不容易灵活调度。建议使用Quartz.Net替代
            ////使用ABP内置的Background Worker
            //var workerManager = IocManager.Resolve<IBackgroundWorkerManager>();
            //workerManager.Add(IocManager.Resolve<TestWorker>());
        }
    }
}
